home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / tools / spsx / spsx_s01.lzh / SRC / pcmplayjob.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  2.6 KB  |  136 lines

  1. #include <method\methodSx.h>
  2. #include <sxlib.h>
  3. #include "pcm8pp.h"
  4. #include "spsx.h"
  5.  
  6. int iPcmPlayMain(tsevent *ts);
  7. int    iPcmPlayInit(tsevent *ts);
  8. int iPcmPlayEnd(tsevent *ts);
  9. int iPcmPlayPause(tsevent *ts);
  10. int    iPcmPlayRestart(tsevent *ts);
  11.  
  12. extern uchar        *pcPcmData[2];                /* PCMバッファ                             */
  13. extern uchar        acFileName[256];            /* 再生ファイル名                         */
  14. extern int        iPlayFlag;                    /* 再生フラグ( 0:再生終了 1:再生中)        */
  15.  
  16. int        iFileHandle;                /* オープンしたファイルハンドル             */
  17. int        iUse;
  18. int     iReadSize;                    /* PCMバッファに取り込まれている大きさ     */
  19.  
  20. int        iPlayFmt;                    /* 再生フォーマット */
  21.  
  22. int        iByteOf1sec;                /* 1秒当たりのByte数 */
  23. int        iPlayByteCount;                /* 再生したByte数   */
  24. int        iReadByteCount;                /* 読み込んだByte数 */
  25. int        iPlayTime;                    /* 再生した秒数 */
  26.  
  27. job_t jobPcmPlay = {     NULL, 
  28.                         iPcmPlayMain,
  29.                         iPcmPlayInit,
  30.                         iPcmPlayEnd,
  31.                         iPcmPlayPause,
  32.                         iPcmPlayRestart,
  33.                         0  };
  34.  
  35. int iPcmPlayMain(tsevent *ts) 
  36. {
  37.     int            i;
  38.  
  39.     int            iRead=0;
  40.  
  41.     int            iRestSize;                /* 再生の残りサイズ */
  42.  
  43.     static int    iCallPlaySize=0;        /* 再生に使ったバッファサイズ */
  44.     static int    iFlagOfEOF=0;
  45.  
  46.     iRestSize = iPcm8Stat(0);
  47.  
  48.     if (iRestSize <= iByteOf1sec / 100 ) {
  49.  
  50.         while( iPcm8Stat(0) > 0);
  51.  
  52.         if ( iReadSize == 0 ) {
  53.  
  54.             iFlagOfEOF = 0;
  55.             UnchainAJob(&jobPcmPlay);
  56.             return 0;
  57.         }
  58.         else {
  59.             iPcm8Play(     0, 
  60.                         iPlayFmt,
  61.                         iReadSize,
  62.                         pcPcmData[iUse] );
  63.             iUse = iUse ^ 0x01;
  64.             iCallPlaySize = iReadSize;
  65.             iRestSize = iReadSize;
  66.             iReadByteCount += iReadSize;
  67.             iReadSize = 0;
  68.         }
  69.     }
  70.  
  71.     if ( iReadSize < PCM_BUF_SIZE && iFlagOfEOF == 0) {
  72.         iRead = DOSREAD(iFileHandle,pcPcmData[iUse]+iReadSize,FILE_READ_SIZE);
  73.         iReadSize += iRead;
  74.  
  75.         if (iRead == 0 ) {
  76.             iFlagOfEOF = 1;
  77.         }
  78.     }
  79.  
  80.     iPlayByteCount = iReadByteCount - iRestSize;
  81.  
  82.     i = iPlayByteCount / iByteOf1sec;
  83.  
  84.     if ( i != iPlayTime ) {
  85.         iPlayTime = i;
  86.         iDrawPlayTime();
  87.     }
  88.  
  89. }
  90.  
  91. int    iPcmPlayInit(tsevent *ts)
  92. {
  93.  
  94.     iFileHandle = TSOpen(acFileName, _O_RDONLY);
  95.  
  96.     if ( iFileHandle <= 0 ) {
  97.         DMError( 1, "ファイルを開けません");
  98.         iPlayFlag = 0;
  99.  
  100.         return -1;
  101.     }
  102.  
  103.     iUse = 0;
  104.     iPlayTime = 0;
  105.     iByteOf1sec = 44100*2*2;
  106.  
  107.     iPlayByteCount = 0;
  108.     iReadByteCount = 0;
  109.  
  110.     iPlayFmt = VOLUME_SIZE_8 | STEREO_16bit_44_1 | OUTPUT_PAN_LR;
  111.  
  112.     iReadSize = DOSREAD(iFileHandle,pcPcmData[iUse],PCM_BUF_SIZE);
  113. }
  114.  
  115. int iPcmPlayEnd(tsevent *ts)
  116. {
  117.     iPlayTime = 0;
  118.     iDrawPlayTime();
  119.  
  120.     iPcm8Stop();
  121.     TSClose(iFileHandle);
  122.  
  123.     iPlayFlag = 0;
  124.  
  125.  
  126. }
  127.  
  128. int iPcmPlayPause(tsevent *ts)
  129. {
  130.     iPcm8Pause();
  131. }
  132.  
  133. int    iPcmPlayRestart(tsevent *ts)
  134. {
  135.     iPcm8Restart();
  136. }